#ifndef SCROLLBAR_H
#define SCROLLBAR_H

#include <boost/signals2.hpp>
#include "view.h"
class ScrollSkin;

class ScrollBar : public View {
public:
     enum Direction {
	  Horizontal,
	  Vertical
     };

     // onPosChange signal template
     typedef boost::signals2::signal<void (int)> OnPosChange;

     ScrollBar(ScrollSkin *skin, Direction dir);
     ~ScrollBar();
     Direction direction() const;
     void setDirection(Direction dir);
     int minimum() const;
     void setMinimum(int min);
     int maximum() const;
     void setMaximum(int max);
     int pos() const;
     void setPos(int pos);
     void setStart(Point start);
     void setLength(int length);
     Rect rect() const;
     void paint(bool all=false);
     void mouseDown(Point p, int button);
     void mouseUp(Point p, int button);
     void mouseMove(Point p, Point dp);
     void mouseExit(Point p);
     const ScrollSkin* scrollSkin();
     std::string toString();

     // connect to onPosChange signal
     boost::signals2::connection onPosChange(const OnPosChange::slot_type &callback);

private:
     Direction m_direction;
     int m_min;
     int m_max;
     int m_pos;
     int m_step;
     ScrollSkin *m_pSkin;
     Point m_start;
     int m_length;
     bool m_dragging;
     int m_dragLength;
     int m_pxPos;
     // signal to emit when pos changes
     OnPosChange m_onPosChange;

     Rect handleRect();
     int scrollLength();
     void setPxPos();
     void setPxPos(int px);
     void dragDone();
     void setPosAtPx(int p);
     Rect upRect();
     Rect downRect();
};

#endif
